import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-16
 * TIME:9:36
 */
public class MyArrryList<I extends Number> implements List<Number> {
    public static final int MAX=10;
    public  int ValidNumber=0;
    public int[] arrryLists;
    public MyArrryList(){
        this.arrryLists=new int[MAX];
        this.arrryLists[0]=32;
        this.arrryLists[1]=12;
        this.arrryLists[2]=34;
        ValidNumber=3;
    }

    @Override
    public void SeqList() {

    }

    @Override
    public void SeqList(int initcapacity) {

    }


    public void expansion(int[] arrry){
        MyArrryList<Number> arrryList=new MyArrryList<Number>();
        arrryList.arrryLists.clone();
    }

    @Override
    public boolean isfull() {
        return ValidNumber==arrryLists.length;
    }

    @Override
    public void checkisfull() {
        if(isfull()){
            arrryLists= Arrays.copyOf(arrryLists,arrryLists .length*2);
        }

    }

    @Override
    public void add(int data) {
        checkisfull();
        this.arrryLists[ValidNumber]=data;
        ValidNumber++;

    }
    private void checkAddpos(int pos)throws posillegityexpition{
        if(pos<1||pos>this.ValidNumber){
            throw new posillegityexpition("数组下标异常"+pos);

        }
    }
    @Override
    public void add(int pos, int data) {
        checkisfull();
        try {
            checkAddpos(pos);
        }catch (posillegityexpition e){
            e.printStackTrace();
            if(pos<0){
                pos=-pos;
                for (int i = this.ValidNumber; i >=pos; i--) {
                    this.arrryLists[ValidNumber]=this.arrryLists[ValidNumber-1];
                }
                this.arrryLists[pos-1]=data;
                ValidNumber++;
            }
            else {
                pos=ValidNumber;
                this.arrryLists[pos]=data;
            }
            return;
        }
        for (int i = this.ValidNumber; i >=pos; i--) {
            this.arrryLists[ValidNumber]=this.arrryLists[ValidNumber-1];
        }
        this.arrryLists[pos-1]=data;
        ValidNumber++;





    }
    private boolean isEmpty(){
        if(this.arrryLists.length==0){
            return true;
        }
        return false;
    }
    @Override
    public boolean contains(int toFind) {
        if(isEmpty() ){
            return false;
        }
        else {
            for (int i = 0; i < this.ValidNumber; i++) {
                if(i==this.arrryLists[i]){
                    return true;
                }
            }
            return false;
        }
    }

    @Override
    public int indexOf(int toFind) {

    }

    @Override
    public int get(int pos) {
        return 0;
    }

    @Override
    public void set(int pos, int value) {

    }

    @Override
    public void remove(int toRemove) {

    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public void clear() {

    }

    @Override
    public void display() {
        for (int i = 0; i <this.ValidNumber; i++) {
            System.out.println(this.arrryLists[i]);
        }
        System.out.println();
    }

}
